import request from '@/utils/request'


// 请求一级列表
//定义返回值类型
export interface reqCategoryItemType {
    id: number;
    name: string;
    // id参数可能没有，所以可选
    category1Id?: number;
    category2Id?: number;
  }

// 返回数组的类型
export type reqCategoryType = reqCategoryItemType[]

export const requestCategory1=()=>{
    return request.get<any,reqCategoryType>('/admin/product/getCategory1')
}

// 请求二级列表
export const requestCategory2=(category1Id:number)=>{
    return request.get<any,reqCategoryType>(`/admin/product/getCategory2/${category1Id}`)
}

// 请求二级列表
export const requestCategory3=(category2Id:number)=>{
    return request.get<any,reqCategoryType>(`/admin/product/getCategory3/${category2Id}`)
}


//请求属性列表
//定义返回值中attrValueList类型
export interface attrValueListItemType{
    id?: number ,
    valueName: string,
    attrId: number | undefined,
    isEdit?:boolean
}
//返回值类型
export interface AttrButeListItemType{
    id?: number,
    attrName: string,
    categoryId: number,
    categoryLevel: number,
    attrValueList: attrValueListItemType[],
    attrValue?:string
}

export type AttrButeListType = AttrButeListItemType[]

export const requestAttrButeList = (category1Id:number,category2Id:number,category3Id:number)=>{
    return request.get<any,AttrButeListType>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}

//删除属性
export const deleteAttrButeList = (attrId:number)=>{
    return request.delete<any,null>(`/admin/product/deleteAttr/${attrId}`)
}

//修改或新增请求， 参数不固定，修改类型定义
export const requestSaveAttrButeList=(newAttrList:AttrButeListItemType)=>{
    return request.post<any,null>(`/admin/product/saveAttrInfo`,newAttrList)
}

